home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctj0587.arc
/
PRTPROC.ASM
< prev
Wrap
Assembly Source File
|
1987-03-16
|
3KB
|
92 lines
; ROUTINE TO CONVERT 1 WORD TO ASCII DIGITS
; BY JOHN A. LEFOR
; AX IS PRINTED
PRTDEC PROC NEAR
PUSH DS
PUSH DI
PUSH DX
PUSH CX
PUSH AX ; SAVE REGS
LEA DI, CS:TBUFF ; DI -> PRINT BUFFER
MOV DX, AX ; ARG PASSED IN AX
MOV CX, 0 ; TRACK FOR # OF DIGITS
OUT1:
PUSH CX
MOV AX, DX ; PLACE NUMBER IN AX
MOV DX, 0
MOV CX, 10
DIV CX ; DIVIDE BY 10
XCHG AX, DX ; GET REMAINDER IN AX
ADD AL, 30H ; CONVERT TO ASCII
MOV CS:[DI], AL ; PLACE IN CHAR BUFFER
INC DI ; -> NEXT SPOT IN BUFFER
POP CX ; COUNT NUMBER OF DIGITS
INC CX
CMP DX,0 ; ANYTHING LEFT
JNZ OUT1 ; IF MORE, LOOP ON
OUT2:
DEC DI ; DI -> NEXT DIGIT
MOV DL, CS:[DI] ; GET THE DIGIT
MOV AH, DISPCHAR
INT DOS ; PRINT THE DIGIT
LOOP OUT2 ; LOOP THRU ALL DIGITS
POP AX ; RESTORE REGS
POP CX
POP DX
POP DI
POP DS ;REGS RESTORED
RET
TBUFF DB 0,0,0,0,0
PRTDEC ENDP
PAGE
; PRTHEX ROUTINE CONVERTS HEX DATA IN AX TO HEX CHARACTERS
; RESULT -> BY DS:DI
; ADAPTED FROM "ADVANCED MS-DOS" BY RAY DUNCAN,
; MICROSOFT PRESS, 1986.
PRTHEX PROC NEAR
PUSH DI
PUSH AX
PUSH CX
PUSH AX
MOV AL,AH
CALL CONV_BYTE ; CONVERT UPPER BYTE
POP AX
CALL CONV_BYTE ; CONVERT LOWER BYTE
POP CX
POP AX
POP DI
RET
PRTHEX ENDP
CONV_BYTE PROC NEAR
SUB AH,AH ; CLEAR UPPER BYTE
MOV CL,16
DIV CL ; DIVIDE BINARY DATA BY 16
CALL MAKPRT ; MAKE A PRINTABLE CHAR
PUSH ES
PUSH DS
POP ES
STOSB
MOV AL,AH
CALL MAKPRT ; THE REMAINDER IS NEXT DIGIT
STOSB
POP ES
RET
CONV_BYTE ENDP
MAKPRT PROC NEAR
ADD AL,'0' ; CONVERT BOTTOM 4 BITS IN AL
CMP AL,'9' ; IS IT A CHARACTER
JLE ENDPRT
ADD AL,'A'-'9'-1 ; FIX THE CHARACTERS
ENDPRT:
RET
MAKPRT ENDP